package demoMod.stsconsole.rewards;

import demoMod.stsconsole.commands.Show;
import demoMod.stsconsole.dungeons.AbstractDungeon;
import demoMod.stsconsole.helpers.LocalizedStrings;
import demoMod.stsconsole.relics.AbstractRelic;
import demoMod.stsconsole.relics.Circlet;

import java.util.List;
import java.util.stream.Collectors;

public class RelicReward extends AbstractReward {
    private final AbstractRelic relic;

    public RelicReward() {
        this(AbstractDungeon.currDungeon.currMapNode.room.getRandomRelicRarity(AbstractDungeon.relicRng));
    }

    public RelicReward(AbstractRelic relic) {
        this.relic = relic;
        this.relic.onRemove();
    }

    public RelicReward(AbstractRelic.RelicRarity rarity) {
        List<AbstractRelic> availableRelics = AbstractDungeon.relicPool.stream().filter(relic1 -> relic1.rarity == rarity && relic1.canSpawn()).collect(Collectors.toList());
        if (availableRelics.isEmpty()) {
            this.relic = new Circlet();
        } else {
            this.relic = availableRelics.get(AbstractDungeon.relicRng.nextInt(availableRelics.size()));
            AbstractDungeon.relicPool.remove(relic);
        }
        this.relic.onRemove();
    }

    @Override
    public boolean claimReward() {
        List<String> strings = LocalizedStrings.getRewardStrings("AbstractReward");
        System.out.println(strings.get(6) + this.relic.name);
        AbstractDungeon.player.obtainRelic(this.relic.id);
        return true;
    }

    @Override
    public void preview() {
        List<String> strings = LocalizedStrings.getRewardStrings("AbstractReward");
        System.out.println(strings.get(1) + " " + this.relic.name);

        List<String> cmdStrings = LocalizedStrings.getCommandStrings("Show");
        System.out.println(cmdStrings.get(25) + relic.getUpdatedDescriptions());
        System.out.println(cmdStrings.get(27) + Show.getRelicRarityString(relic.rarity));
        System.out.println(cmdStrings.get(26) + relic.flavor);
    }

    @Override
    public void skipped() {

    }
}
